#include <iostream>
#include <algorithm>
#include <cmath>

int const inf = 1<<27;
int const maxn = 3003;
int const maxm = 3003;
int f[maxn][maxm];
int da[maxn];
int n, m;

int main()
{
	std::ios::sync_with_stdio(false);
	int T;
	std::cin >> T;
	for (int ti = 1; ti <= T; ti++) {
		std::fill(f[0], f[0] + maxn * maxm, inf);
		std::cout << "Case #" << ti << ": ";

		std::cin >> n >> m;
		for (int i = 1; i <= n; i++) std::cin >> da[i];

		for (int i = 0; i <= m; i++) f[0][i] = 0;

		int ans = inf;
		for (int i = 1; i <= n; i++)
			for (int j = 0; j <= m; j++) {
				if (f[i-1][j] >= inf) continue;
				int sum = -1;
				for (int k = i; k <= n; k++) {
					sum += da[k] + 1;
					if (sum > m) break;
					f[k][sum] = std::min(f[k][sum], f[i-1][j] + std::abs(sum - j));
				}
				ans = std::min(ans, f[n][sum]);
			}

		std::cout << ans << '\n';
	}
}

